function EventsEmmiter() {
    this.events = {} //监听放到这个对象中保存
}
// listeners
EventsEmmiter.prototype.on = EventsEmmiter.prototype.addListener = function (
  type,
  listener
) {
  if (this.events[type]) {
    this.events[type].push(listener);
  } else {
    this.events[type] = [listener];
  }
};
EventsEmmiter.prototype.once = function(type,listener){
    function wrapper(...rest){
        listener.apply(this,rest)
        this.removeListener(type,wrapper)
    }
    this.on(type,wrapper)
}
EventsEmmiter.prototype.removeListener = function(type,listener){
    if(this.events[type]){
        this.events[type] = this.events[type].filter(l=>l!=listener)
    }
}
EventsEmmiter.prototype.removeall = function(type){
    delete this.events[type]
}
EventsEmmiter.prototype.emit = function (type, ...rest) {
  this.events[type] &&
    this.events[type].forEach((listener) => {
      listener.apply(this, rest);
    });
};
module.exports = EventsEmmiter;
